import { View } from "../../../../mvc/core/View";
import { LayerManager } from "../../../manager/LayerManager";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { Language } from "../../../../../extend/language/Language";
import { CopyMountBoxCell } from "./CopyMountBoxCell";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../resource/ResFileConst";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { CopyMountBackInfo } from "./CopyMountBackInfo";
import { Global } from "../../../../../com/gengine/global/Global";
import { CopyMountFrontInfo } from "./CopyMountFrontInfo";
import { SceneRange } from "../../../scene/map/SceneRange";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
type int = number;
//class CopyMountBoxView
    
    export  class CopyMountBoxView extends View
    {
        constructor()
        {
            super();
            this._boxArr = [];
            layer = LayerManager.uiLayer;
            this.initView();
            return;
        }

        /* internal  */initView(): void
        {
            var loc1=null;
            this._bg = ObjCreate.createBitmap("", 0, 0);
            addChild(this._bg);
            ObjCreate.createBg(63, 192, 770, 4, this, ImagesConst.Line);
            this._closeBtn = ObjCreate.createGButton(Language.getString(20025), 383, 203, 74, 24, this, "ButtonRedMini");
            this._closeBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onCloseBtnClick);
            var loc2=0;
            while (loc2 < 4) 
            {
                loc1 = new CopyMountBoxCell();
                loc1.x = 110 + loc2 * 169;
                loc1.y = 48;
                addChild(loc1);
                this._boxArr.push(loc1);
                ++loc2;
            }
            this._helpTx = ObjCreate.createGTextField("", 470, 203, 66, 20, this, GlobalStyle.textFormat5);
            this._helpTx.htmlText = Language.getString(71127);
            this._helpTx.toolTipData = "<textFormat leading=\'4\'>" + Language.getString(74202) + "</textFormat>";
            this._debugTx = ObjCreate.createGTextField("", 470, 223, 250, 20, this, GlobalStyle.textFormat5);
            this._debugTx.visible = false;
            LoaderHelp.addResCallBack(ResFileConst.copyMount, this.onLoadBmResource);
            return;
        }

        protected onCloseBtnClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.CopyMountClickClose, this.bossId));
            return;
        }

        /* internal  */onLoadBmResource(): void
        {
            this._bg.bitmapData = GlobalClass.getBitmapData(ImagesConst.copyMount_bg);
            return;
        }

        public setBackData(arg1: Array<any>): void
        {
            var loc1=null;
            var loc2=arg1.length;
            var loc3="";
            if (loc2 > 0) 
            {
                this.bossId = (arg1[0] as CopyMountBackInfo).bossId;
            }
            var loc4=0;
            while (loc4 < loc2) 
            {
                loc1 = this._boxArr[loc4] as CopyMountBoxCell;
                loc1.setBackData(arg1[loc4] as CopyMountBackInfo);
                loc3 = loc3 + ((arg1[loc4] as CopyMountBackInfo).modelId + " / ");
                ++loc4;
            }
            if (Global.isDebugModle) 
            {
                this._debugTx.visible = true;
                this._debugTx.text = loc3;
            }
            else 
            {
                this._debugTx.visible = false;
            }
            return;
        }

        public setFrontData(arg1: CopyMountFrontInfo): void
        {
            var loc2=null;
            var loc1=this._boxArr.length;
            var loc3=0;
            while (loc3 < loc1) 
            {
                loc2 = this._boxArr[loc3];
                if (arg1.bossId == loc2.backInfo.bossId && arg1.modelId == loc2.backInfo.modelId) 
                {
                    loc2.setFrontData(arg1.itemCode, arg1.itemNum);
                }
                ++loc3;
            }
            return;
        }

        public stageResize(): void
        {
            this.x = (SceneRange.display.width - 817) * 0.5;
            this.y = (SceneRange.display.height - 242) * 0.5;
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            this.stageResize();
            return;
        }

        public isAllOpenCurBoss(): Boolean
        {
            var loc2=null;
            var loc1=this._boxArr.length;
            var loc3=0;
            while (loc3 < loc1) 
            {
                loc2 = this._boxArr[loc3];
                if (loc2.isBack) 
                {
                    return false;
                }
                ++loc3;
            }
            return true;
        }

        public updateCost(arg1: int): void
        {
            var loc2=null;
            var loc1=this._boxArr.length;
            var loc3=0;
            while (loc3 < loc1) 
            {
                loc2 = this._boxArr[loc3];
                if (!loc2.backInfo.isHad) 
                {
                    loc2.updateCost(arg1);
                }
                ++loc3;
            }
            return;
        }

        /* internal */ /* var */_bg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_closeBtn: GButton;

        /* internal */ /* var */_helpTx: GTextFiled;

        /* internal */ /* var */_boxArr: Array<any>;

        public /* var */bossId: int;

        /* internal */ /* var */_debugTx: Object /* flash.text.TextField */;
    }
